package com.stock.demo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.stock.demo.R;
import com.stock.demo.adapter.viewholder.StockViewHolder;
import com.stock.demo.function.share.view.StockDetailActivity;
import com.stock.demo.model.MarketDetailBean;

import java.util.ArrayList;

/**
 * Created by XuZhaoyu on 2017/7/15.
 */

public class MarketViewFootAdapter extends StockBaseAdapter<MarketDetailBean> {

    private Context mContext;

    public MarketViewFootAdapter(Context context, ArrayList<MarketDetailBean> data) {
        super(context, data);
        mContext = context;
    }

    @Override
    public int setLayoutResId() {
        return R.layout.view_market_foot_item;
    }

    @Override
    public void onBindViewHolder(StockViewHolder holder, int position) {
        TextView tvName = (TextView) holder.itemView.findViewById(R.id.tv_market_list_foot_name);
        TextView tvSymbol = (TextView) holder.itemView.findViewById(R.id.tv_market_list_foot_symbol);
        TextView tvCurrentPrice = (TextView) holder.itemView.findViewById(R.id.tv_market_list_foot_current_price);
        TextView tvChangePercent = (TextView) holder.itemView.findViewById(R.id.tv_market_list_foot_change_percent);
        final MarketDetailBean bean = getItem(position);
        if (bean != null) {
            tvName.setText(bean.mName);
            tvSymbol.setText(bean.mSymbol);
            tvCurrentPrice.setText(bean.mCurrentPrice);
            tvChangePercent.setText(bean.mChangePercent);
            if (bean.mChangePercent.startsWith("-")) {
                tvCurrentPrice.setTextColor(mContext.getResources().getColor(R.color.colorGreen));
                tvChangePercent.setTextColor(mContext.getResources().getColor(R.color.colorGreen));
            } else {
                tvCurrentPrice.setTextColor(mContext.getResources().getColor(R.color.colorRed));
                tvChangePercent.setTextColor(mContext.getResources().getColor(R.color.colorRed));
            }
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    StockDetailActivity.startAction(mContext, bean);
                }
            });
        }
        if (position == getItemCount() - 1) {
            holder.itemView.findViewById(R.id.iv_market_foot_line).setVisibility(View.INVISIBLE);
        }
    }
}
